import React, { useState } from 'react';
import {
  Col,
  Row,
  Form,
  Input,
  Divider,
  Button,
  Upload,
  Descriptions,
  message,
  Spin,
} from 'antd';
import request from '@/http';
import { UploadOutlined } from '@ant-design/icons';
import { Homework } from '@/pages/login/service';

export default function index() {
  const getData = async () => {
    await request
      .post(
        '/student/Operation/StudentViewApproval/' +
          Homework.getHomeworkIds().id,
      )
      .then((response: any) => {
        setspinning(false);
        if (response.code == 200) {
          setdata(response.data);
        } else {
          message.error(response.message);
        }
      });
  };
  const [data, setdata] = useState({ score: '', teacherRemark: '' }); //获取数据
  React.useEffect(() => {
    if (Homework.getHomeworkIds().state == 1) {
      getData();
    }
  }, []);
  const [spinning, setspinning] = useState(true);
  return (
    <>
      <Spin spinning={spinning} size="large">
        <Row justify="center">
          <Col span={22}>
            <Form.Item>
              {Homework.getHomeworkIds().state == 1 ? (
                <Descriptions>
                  <Descriptions.Item
                    label="得分"
                    contentStyle={{ fontSize: '50px', color: 'red' }}
                  >
                    {data.score}
                  </Descriptions.Item>
                </Descriptions>
              ) : (
                <Input style={{ width: 200 }} placeholder="请录入" />
              )}
            </Form.Item>
          </Col>
          <Col span={22}>
            {Homework.getHomeworkIds().state == 1 ? (
              <Form.Item label="相关附件">
                <Col span={22}>XXXXXX</Col>
              </Form.Item>
            ) : (
              <Form.Item label="上传相关附件">
                <Col span={22}>
                  <Upload>
                    <Button type="primary" icon={<UploadOutlined />}>
                      上传文件
                    </Button>
                  </Upload>
                </Col>
              </Form.Item>
            )}
          </Col>
          <Divider></Divider>
          <Col span={22}>
            <Descriptions title="评语">
              <Descriptions.Item>{data.teacherRemark}</Descriptions.Item>
            </Descriptions>
          </Col>
        </Row>
      </Spin>
    </>
  );
}
